import React from 'react'
import { useEffect } from 'react'
import PubSub from 'pubsub-js'
import Son1 from './Son1'
import Son2 from './Son2'
import { useState } from 'react'

export default function Father() {
    let [data,setData] = useState('')
    useEffect(() => {
        // 订阅峰峰的消息
        let topicId2 = PubSub.subscribe('fengfeng', (msg, data) => {
            console.log('Father msg: ', msg)
            console.log('Father data: ', data)

            setData(data)
        })
        return ()=>{
            PubSub.unsubscribe(topicId2)
        }
    }, [])
    return (
        <div>
            <h3>Father</h3>
            <p>Father data: {data}</p>
            <Son1 />
            <hr />
            <Son2 />
        </div>
    )
}
